package lambda;

import java.util.Arrays;
import java.util.Comparator;

/**
 * Lambda基础
 */
public class LambdaBasis {
    public static void main(String[] args) {
        /**
         * 在Java程序中，我们经常遇到一大堆单方法接口，即一个接口只定义了一个方法：
         * Comparator
         * Runnable
         * Callable
         * 可以用Lambda表达式替换单方法接口
         */

        //以实现字符串数组排序为例
        String[] arrayStr = new String[]{"a","d","c","o","r","e","p"};

        //非lambda
        Arrays.sort(arrayStr, new Comparator<String>(){
            @Override
            public int compare(String s1, String s2) {
                return s1.compareTo(s2);
            }
        });

        //lambda
        Arrays.sort(arrayStr,(s1,s2)->{ return s1.compareTo(s2);});

        System.out.println("后");
        for (String s : arrayStr) {
            System.out.println(s);
        }


    }
}
